/**
 *  获取 url 后面通过?传参的参数
 * @param {String} name
 */
export function getQueryString(name) {
  const reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i')
  const url = window.location.href
  const search = url.substring(url.lastIndexOf('?') + 1)
  const r = search.match(reg)
  if (r != null) return unescape(r[2])
  return null
}

/**
 * 获取 url 后面通过?传参的参数
 */
export const getUrlParam = function () {
  let url = window.location.href
  let requestObj = new Object()
  let ind = url.indexOf('?')
  if (ind != -1) {
    let str = url.substr(ind + 1)
    let strs = str.split('&')
    for (let i = 0; i < strs.length; i++) {
      requestObj[strs[i].split("=")[0]] = strs[i].split("=")[1]
    }
  }
  return requestObj
}

/***
 * 获取url参数
 */
const getUrlParam = (name) => {
  let reg = new RegExp('(^|&?)' + name + '=([^&]*)(&|$)', 'i');
  let r = window.location.href.substr(1).match(reg);
  if (r != null) {
    return decodeURI(r[2]);
  }
  return undefined;
}